# @Author : wangyuchen
# @Time : 2021-05-16 10:33

import os

if __name__ == '__main__':
    if not os.path.exists('val2'):
        os.mkdir('val2')
        with open('val_anno.txt', 'r') as f:
            items = f.readlines()
            items = [item.strip().split() for item in items]
        iid_to_cid = {item[0]: item[1] for item in items}
        for rt, dirs, files in os.walk('./val'):
            for f in files:
                img1 = open('./val/'+f, 'rb')
                x = img1.read()
                if not os.path.exists('./val2/'+str(iid_to_cid[f])):
                    os.mkdir('./val2/'+str(iid_to_cid[f]))
                img2 = open('./val2/'+str(iid_to_cid[f])+'/'+f, 'wb')
                img2.write(x)
                img1.close()
                img2.close()
